package com.kingyea.mobilepolice.apimanage.association.controller;

import com.kingyea.mobilepolice.apimanage.association.bean.ServiceRequesterAssociation;
import com.kingyea.mobilepolice.apimanage.association.service.ServiceRequesterAssociationService;
import com.kingyea.mobilepolice.apimanage.log.OperateType;
import com.kingyea.mobilepolice.apimanage.log.OperationLogAnnotation;
import com.kingyea.mobilepolice.apimanage.provider.vo.ProviderVO;
import com.kingyea.mobilepolice.apimanage.serviceinfo.bean.ServiceInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ServiceRequesterAssociation 控制层
 * @date Created in 2018-03-10 18:52:52
 */
@RequestMapping(value = "/serviceRequesterAssociation")
@RestController
public class ServiceRequesterAssociationController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRequesterAssociationController.class);

    @Autowired
    private ServiceRequesterAssociationService serviceRequesterAssociationService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @OperationLogAnnotation(operateName = "查询全部接口关联关系", operateType = OperateType.SELECT, module = "association")
    @RequestMapping(method = RequestMethod.GET)
    public Object list() throws Exception {
        return serviceRequesterAssociationService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param requesterId
     * @param serviceId
     * @return
     */
    @OperationLogAnnotation(operateName = "通过ID查找接口关联关系对象", operateType = OperateType.SELECT, module = "association")
    @RequestMapping(value = "/{requesterId}/{serviceId}", method = RequestMethod.GET)
    public Object detail(@PathVariable Integer requesterId, @PathVariable Integer serviceId) throws Exception {
        return serviceRequesterAssociationService.getById(requesterId, serviceId);
    }

    /**
     * 创建
     *
     * @param serviceRequesterAssociation
     * @return
     */
    @OperationLogAnnotation(operateName = "创建接口关联关系对象", operateType = OperateType.INSERT, module = "association")
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody ServiceRequesterAssociation serviceRequesterAssociation) throws Exception {
        return serviceRequesterAssociationService.save(serviceRequesterAssociation);
    }

    /**
     * 更新
     *
     * @param serviceRequesterAssociation
     * @return
     */
    @OperationLogAnnotation(operateName = "更新接口关联关系对象", operateType = OperateType.UPDATE, module = "association")
    @RequestMapping(method = RequestMethod.PUT)
    public Object update(@RequestBody ServiceRequesterAssociation serviceRequesterAssociation) throws Exception {
        return serviceRequesterAssociationService.update(serviceRequesterAssociation);
    }

    /**
     * 删除
     *
     * @param requesterId
     * @param serviceId
     * @return
     */
    @OperationLogAnnotation(operateName = "删除接口关联关系对象", operateType = OperateType.DELETE, module = "association")
    @RequestMapping(value = "/{requesterId}/{serviceId}", method = RequestMethod.DELETE)
    public Object delete(@PathVariable Integer requesterId, @PathVariable Integer serviceId) throws Exception {
        return serviceRequesterAssociationService.deleteById(requesterId, serviceId);
    }

    /**
     * 根据搜索条件搜索关联信息
     *
     * @param map
     * @return com.device.mall.utils.page.PageInfo
     * @author Mr.Lin
     * @date 2017/11/20 15:57
     */
    @ApiOperation(value = "根据搜索条件搜索关联信息", notes = "", response = ServiceInfo.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "status", value = " 状态：1:注册未审核，2:变更未审核，3:审核通过，4:审核不通过 ", required = false, dataType = "int")
            , @ApiImplicitParam(name = "pageNum", value = "第几页", required = true, dataType = "int")
            , @ApiImplicitParam(name = "pageSize", value = "每页数据数量大小", required = true, dataType = "int")
            , @ApiImplicitParam(name = "keyword", value = " 关键字keyword，订单号和代理商名字 ", required = false, dataType = "Integer")
            , @ApiImplicitParam(name = "searchType", value = " 搜索类型（name.接口名称 serialNo.接口标识 organization.管理单位名称  all.所有） ", required = true, dataType = "String")
    })
    @OperationLogAnnotation(operateName = "根据搜索条件搜索关联关系信息", operateType = OperateType.SELECT, module = "association")
    @RequestMapping(value = "/searchByCondition", method = RequestMethod.POST)
    public Object searchByCondition(@RequestBody Map<String, Object> map) throws Exception {
        return serviceRequesterAssociationService.searchByCondition(map);
    }


    /**
     * 审核
     *
     * @param map
     * @return java.lang.Object
     * @author Mr.Lin
     * @date 2018/3/9 15:51
     */
    @ApiOperation(value = "审核", notes = "", response = ProviderVO.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "requesterId", value = "请求者ID", required = true, dataType = "int")
            , @ApiImplicitParam(name = "serviceId", value = "接口ID", required = true, dataType = "int")
            , @ApiImplicitParam(name = "status", value = "审核状态：1:注册未审核，2:变更未审核，3:审核通过，4:审核不通过", required = true, dataType = "int")
    })
    @OperationLogAnnotation(operateName = "审核关联关系信息", operateType = OperateType.UPDATE, module = "association")
    @RequestMapping(value = "/check", method = RequestMethod.POST)
    public Object check(@RequestBody Map<String, Object> map) throws Exception {
        return serviceRequesterAssociationService.check(map);
    }

}
